<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'ForEach.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
<!-- c:forEach标签 -->
	<h3>JSTL: -- forEach标签实例</h3>
	<hr/>
	<%
		List<String> list=new ArrayList<String>();
		list.add("盲僧");
		list.add("安妮");
		list.add("莫甘娜");
		list.add("剑圣");
		list.add("蛮王");
		list.add("提莫");
		list.add("赵信");
		list.add("赏金");
		request.setAttribute("a",list);
	 %>
	 <h4>对数组进行循环</h4>	
	 <c:forEach var="name" items="${a}">
    &nbsp;<c:out value="${name }"></c:out><br>
     </c:forEach>
     <h4>对部分数组进行循环</h4>	
     <!-- 下标从0开始 -->
     <c:forEach var="name" items="${a}" begin="1" end="7" step="2">
     &nbsp;<c:out value="${name}" /><br>
     </c:forEach>
     <h4>step属性的用法</h4>	
     <c:forEach var="i" begin="1" end="5" step="2">
   		i的值:<c:out value="${i}"/><p>
	 </c:forEach>
	 <h4>varStatus属性的用法</h4>
	 <c:forEach var="name" items="${a}" begin="0" end="4" step="2" varStatus="s">
	     &nbsp;<c:out value="${name}" />的四种属性：<br>
	     &nbsp;&nbsp;索引：<c:out value="${s.index}" /><br>
	     &nbsp;&nbsp;总共已迭代的次数：<c:out value="${s.count}" /><br>
	     &nbsp;&nbsp;是否为第一个位置：<c:out value="${s.first}" /><br>
	     &nbsp;&nbsp;是否为最后一个位置：<c:out value="${s.last}" /><br>
     </c:forEach>
     <!-- 下面来讲c:forTokens标签,用于浏览字符串，并根据指定的字符串截取字符串
      delims指定使用什么符号作为分隔符-->
      
     <!-- c:forTokens标签 -->
     <h4>c:forTokens标签</h4>
     <c:forTokens items="北,京,欢,迎,您" delims="," var="c">
     	<c:out value="${c}"></c:out>
     </c:forTokens>
     
  </body>
</html>
